﻿/* 2014/2/12 */
using System;

namespace PictureManager.ClassifyFile
{
    /// <summary>
    /// The rule of files corresponding to a folder.
    /// </summary>
    class CorrespondenceRule
    {
        private const string _SEPARATOR = "*";

        /// <summary>
        /// The pattern of file name.
        /// </summary>
        private string _fileNamePattern;
        /// <summary>
        /// The aPath of the corresponded folder.
        /// </summary>
        private string _folderPath;
        /// <summary>
        /// Whether this folder a sub folder of root folder.
        /// </summary>
        private bool _isSubFolder;
        /// <summary>
        /// The option of correspondence.
        /// </summary>
        private CorrespondOption _correspondOption;

        /// <summary>
        /// Initialize a instance of CorrespondenceRule.
        /// </summary>
        /// <param name="fileNamePattern">Pattern of file name.</param>
        /// <param name="selectedFolderPath">The aPath of the corresponded folder.</param>
        /// <param name="isSubFolder">Whether this folder a sub folder of root folder.</param>
        /// <param name="correspondOption">The option of correspondence.</param>
        public CorrespondenceRule(string fileNamePattern, string folderPath, bool isSubFolder, CorrespondOption correspondOption)
        {
            _fileNamePattern = fileNamePattern;
            _folderPath = folderPath;
            _isSubFolder = isSubFolder;
            _correspondOption = correspondOption;
        }

        /// <summary>
        /// Initialize a instance of CorrespondenceRule by a escape string.
        /// </summary>
        /// <param name="transforredString">The escape string.</param>
        public CorrespondenceRule(string escapeString)
        {
            string[] dataStrings = escapeString.Split(new string[] { _SEPARATOR }, StringSplitOptions.None);
            if (dataStrings.Length == 4)
            {
                _fileNamePattern = dataStrings[0];
                _folderPath = dataStrings[1];
                _isSubFolder = Boolean.Parse(dataStrings[2]);
                _correspondOption = (CorrespondOption)Int32.Parse(dataStrings[3]);
            }
            else
            {
                _fileNamePattern = null;
                _folderPath = null;
                _isSubFolder = false;
                _correspondOption = CorrespondOption.Contain;
            }
        }

        /// <summary>
        /// Get the escape string of this CorrespondenceRule.
        /// </summary>
        public string EscapeString
        {
            get
            {
                string[] dataStrings = new string[4];
                dataStrings[0] = _fileNamePattern;
                dataStrings[1] = _folderPath;
                dataStrings[2] = _isSubFolder.ToString();
                dataStrings[3] = ((int)_correspondOption).ToString();
                return String.Join(_SEPARATOR, dataStrings);
            }
        }

        /// <summary>
        /// Get or set the pattern of file name.
        /// </summary>
        public string FileNamePattern
        {
            get { return _fileNamePattern; }
            set { _fileNamePattern = value; }
        }
        /// <summary>
        /// Get or set the aPath of the corresponded folder.
        /// </summary>
        public string FolderPath
        {
            get { return _folderPath; }
            set { _folderPath = value; }
        }
        /// <summary>
        /// Whether this folder a sub folder of root folder.
        /// </summary>
        public bool IsSubFolder
        {
            get { return _isSubFolder; }
            set { _isSubFolder = value; }
        }
        /// <summary>
        /// Get or set the option of correspondence.
        /// </summary>
        public CorrespondOption CorrespondOption
        {
            get { return _correspondOption; }
            set { _correspondOption = value; }
        }
    }
}
